<?php require_once('Connections/hitekforyou.php'); ?>
<?php
// Load the common classes
require_once('includes/common/KT_common.php');

// Load the tNG classes
require_once('includes/tng/tNG.inc.php');

// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("");

// Make unified connection variable
$conn_hitekforyou = new KT_connection($hitekforyou, $database_hitekforyou);

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$maxRows_sanpham = 12;
$pageNum_sanpham = 0;
if (isset($_GET['pageNum_sanpham'])) {
  $pageNum_sanpham = $_GET['pageNum_sanpham'];
}
$startRow_sanpham = $pageNum_sanpham * $maxRows_sanpham;

$colname_sanpham = "-1";
if (isset($_GET['idHang'])) {
  $colname_sanpham = $_GET['idHang'];
}
mysql_select_db($database_hitekforyou, $hitekforyou);
$query_sanpham = sprintf("SELECT * FROM sanpham WHERE idHang = %s and AnHien =1 ORDER BY idSP DESC", GetSQLValueString($colname_sanpham, "int"));
$query_limit_sanpham = sprintf("%s LIMIT %d, %d", $query_sanpham, $startRow_sanpham, $maxRows_sanpham);
$sanpham = mysql_query($query_limit_sanpham, $hitekforyou) or die(mysql_error());
$row_sanpham = mysql_fetch_assoc($sanpham);

if (isset($_GET['totalRows_sanpham'])) {
  $totalRows_sanpham = $_GET['totalRows_sanpham'];
} else {
  $all_sanpham = mysql_query($query_sanpham);
  $totalRows_sanpham = mysql_num_rows($all_sanpham);
}
$totalPages_sanpham = ceil($totalRows_sanpham/$maxRows_sanpham)-1;


$queryString_sanpham = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_sanpham") == false && 
        stristr($param, "totalRows_sanpham") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_sanpham = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_sanpham = sprintf("&totalRows_sanpham=%d%s", $totalRows_sanpham, $queryString_sanpham);

// Make a logout transaction instance
$logoutTransaction = new tNG_logoutTransaction($conn_hitekforyou);
$tNGs->addTransaction($logoutTransaction);
// Register triggers
$logoutTransaction->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "thoat");
$logoutTransaction->registerTrigger("END", "Trigger_Default_Redirect", 99, "Index.php");
// Add columns
// End of logout transaction instance

// Make a login transaction instance
$loginTransaction = new tNG_login($conn_hitekforyou);
$tNGs->addTransaction($loginTransaction);
// Register triggers
$loginTransaction->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "dangnhap");
$loginTransaction->registerTrigger("END", "Trigger_Default_Redirect", 99, "{kt_login_redirect}");
// Add columns
$loginTransaction->addColumn("kt_login_user", "STRING_TYPE", "POST", "user_name");
$loginTransaction->addColumn("kt_login_password", "STRING_TYPE", "POST", "user_pass");
// End of login transaction instance

// Execute all the registered transactions
$tNGs->executeTransactions();

// Get the transaction recordset
$rscustom = $tNGs->getRecordset("custom");
$row_rscustom = mysql_fetch_assoc($rscustom);
$totalRows_rscustom = mysql_num_rows($rscustom);


$TFM_LimitLinksEndCount = 12;
$TFM_temp = $pageNum_sanpham + 1;
$TFM_startLink = max(1,$TFM_temp - intval($TFM_LimitLinksEndCount/2));
$TFM_temp = $TFM_startLink + $TFM_LimitLinksEndCount - 1;
$TFM_endLink = min($TFM_temp, $totalPages_sanpham + 1);
if($TFM_endLink != $TFM_temp) $TFM_startLink = max(1,$TFM_endLink - $TFM_LimitLinksEndCount + 1);


?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Trang chủ</title>
<link href="css.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="stmenu.js"></script>
<script src="AC_RunActiveContent.js" type="text/javascript"></script>
<link href="includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="includes/common/js/base.js" type="text/javascript"></script>
<script src="includes/common/js/utility.js" type="text/javascript"></script>
<script src="includes/skins/style.js" type="text/javascript"></script>
</head>

<body>
<div id="container">
  <div id="header">
   <?php include("banner.php"); ?> 
  </div>
  <div id="menu">
   <script type="text/javascript" src="menu.js"></script>

  </div>
  <div id="main">
    <!-- Start Div Left Main -->
    <?php include("leftmain.php"); ?>
        <!-- End Div Left Main -->
    <!-- Start Div right Main -->
   <div id="rightmain">


    <?php
//Show If User Is Logged In (region1)
$isLoggedIn = new tNG_UserLoggedIn($conn_hitekforyou);
//Grand Levels: Level
if ($isLoggedIn->Execute()) {
?>
<form id="DangXuat" name="dangxuat" method="post" action="">
          <table width="184" border="0" cellspacing="0" cellpadding="0" align="center">
            <tbody>
              <tr>
                <td align="center"><img src="images/dang-nhap.jpg" alt="6" width="184" height="41" /></td>
              </tr>
              <tr>
                <td height="170" valign="top" background="images/dang-nhap-bg.jpg" style="padding:5px 5px 5px 5px; background-repeat:no-repeat;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                      <tr>
                        <td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                            <tbody>
                              <tr>
                                <td><div align="center"><strong>Chào
                                    <?php echo $_SESSION['kt_TenKH']; ?> </strong></div></td>
                              </tr>
                              <tr>
                                <td height="8"><img src="images/spacer.gif" alt="5" width="1" height="1" /></td>
                              </tr>
                              <tr>
                                <td><div align="center"><strong><a href="doithongtincanhan.php" class="lienket">Đổi thông tin cá nhân</a></strong></div></td>
                              </tr>
                              <tr>
                                <td height="5"><img  src="images/spacer.gif" alt="4" width="1" height="1" /></td>
                              </tr>
                              <tr>
                                <td><div align="center">
                                  </div></td>
                              </tr>
                              <tr>
                                <td height="5"><img src="images/spacer.gif" alt="3" width="1" height="1" /></td>
                              </tr>
                              <tr>
                                <td>&nbsp;</td>
                              </tr>
                              <tr>
                                <td height="5"><img  src="images/spacer.gif" alt="2" width="1" height="1" /></td>
                              </tr>
                              <tr>
                                <td height="5" align="center"><?php
	echo $tNGs->getErrorMsg();
?><input type="submit" name="thoat" id="button2" value="Thoát" onclick="funABC()" /></td>
                              </tr>
                              <tr>
                                <td height="5"><img src="images/spacer.gif" alt="1" width="1" height="1" /></td>
                              </tr>
                            </tbody>
                        </table></td>
                      </tr>
                      <tr>
                        <td valign="top"><label>
                            <div align="center"></div>
                          </label></td>
                      </tr>
                    </tbody>
                  </table>
                    <label>
                    <div align="center"></div>
                  </label></td>
              </tr>
            </tbody>
          </table>
            </form>


      <?php 
// else Show If User Is Logged In (region1)
} else { ?>
      <form id="DangNhap" name="DangNhap" method="post" action="">
          <table width="184" border="0" cellspacing="0" cellpadding="0" align="center">
            <tbody>
              <tr>
                <td align="center"><img src="images/dang-nhap.jpg" width="184" height="41" /></td>
              </tr>
              <tr>
                <td height="170" valign="top" background="images/dang-nhap-bg.jpg" style="padding:5px 5px 5px 5px; background-repeat:no-repeat;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                      <tr>
                        <td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                            <tbody>
                              <tr>
                                <td><div align="center"><strong>Tên đăng nhập</strong></div></td>
                              </tr>
                              <tr>
                                <td height="8"><img src="images/spacer.gif" width="1" height="1" /></td>
                              </tr>
                              <tr>
                                <td><div align="center">
                                  <input type="text" name="user_name" id="user_name" />
                                </div></td>
                              </tr>
                              <tr>
                                <td height="5"><img src="images/spacer.gif" width="1" height="1" /></td>
                              </tr>
                              <tr>
                                <td><div align="center"><strong>Mật khẩu</strong></div></td>
                              </tr>
                              <tr>
                                <td height="5"><img src="images/spacer.gif" width="1" height="1" /></td>
                              </tr>
                              <tr>
                                <td><div align="center">
                                  <input type="password" name="user_pass" id="user_pass" />
                                </div></td>
                              </tr>
                              <tr>
                                <td height="5"><img src="images/spacer.gif" width="1" height="1" /></td>
                              </tr>
                              <tr>
                                <td height="5" align="center"><input type="submit" name="dangnhap" id="button" value="Đăng nhập" /></td>
                              </tr>
                              <tr>
                                <td height="5"><img src="images/spacer.gif" width="1" height="1" /></td>
                              </tr>
                            </tbody>
                        </table></td>
                      </tr>
                    </tbody>
                  </table>
                    <label>
                    <div align="center"></div>
                  </label></td>
              </tr>
            </tbody>
          </table>
        </form> <!-- End Form Đăng nhập -->
  <?php
}
//End Show If User Is Logged In (region1)
?>

<div id="giohang">
         <?php include "hiengiohang.php"; ?>
        </div>

     <!-- End Div Gio Hang -->   
     
      <table width="184" border="0" cellspacing="0" cellpadding="0" align="center">
        <tbody>
          <tr>
            <td align="center"><img src="images/tin-moi-nhat.jpg" width="184" height="40" /></td>
          </tr>
          <tr>
            <td height="226" valign="top" background="images/tin-moi-nhat-bg.jpg" style="padding:5px 5px 5px 5px; background-repeat:no-repeat;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                  <tr>
                    <td>
<div style="height:200px;">
<marquee behavior="scroll" direction="up" height="200px" scrolldelay="700">
<div style="padding-bottom:2px; padding-top:5px;padding-left:5px;"><img src="images/arrow2.gif" width="9" height="7" />Tin mới</div>
</marquee>
</div></td>
                  </tr>
                </tbody>
            </table></td>
          </tr>
        </tbody>
      </table> <!-- End Table Tin tuc -->
    </div>
    
    
    
    
        <!-- End Div right Main -->
    <div id="content">
   <table width="600" border="0" align="center" cellpadding="1" cellspacing="1">
        <tr>
          <td><table width="600" border="0" align="center" cellpadding="0" cellspacing="0" id="IPad">
            <tbody>
              <tr>
                <td valign="top" bgcolor="#FFFFFF"><div>
                    <table width="600" border="0" align="center" cellpadding="0" cellspacing="0" id="main2">
                      <tr>
                        <td><table width="100%" border="0" cellpadding="0" cellspacing="0" id="IPad2">
                            <tbody>
                              <tr>
                                <td width="9"><img src="images/bc-t-l.gif" width="9" height="9" /></td>
                                <td bgcolor="#FFFFFF"><img src="images/spacer.gif" width="1" height="1" /></td>
                                <td width="11"><img src="images/bc-t-r.gif" width="11" height="9" /></td>
                              </tr>
                              <tr>
                                <td bgcolor="#FFFFFF"><img src="images/spacer.gif" width="1" height="1" /></td>
                                <td align="left" valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                                      <tbody>
                                        <tr>
                                          <td>&nbsp;</td>
                                        </tr>
                                        <tr>
                                          <td><table style="padding-left: 7px; padding-right: 7px;" width="100%" border="0" cellpadding="0" cellspacing="0" height="20">
                                              <tbody>
                                                <tr>
                                                  <td valign="top" align="left" bgcolor="#ffffff" height="20"><table width="100%" border="0" cellpadding="1" cellspacing="1">
                                                      <tbody>
                                                        <tr valign="top" bgcolor="#ffffff">
                                                          <td valign="top" width="25%" height="100%"><div align="center">
                                                              <table width="170" border="1" align="center" class="khungsanpham">
                                                                <tr>
                                                                  <?php
do { // horizontal looper version 3
?>
                                                                  <td><table width="170" border="0" cellpadding="0" cellspacing="0">
                                                                      <tbody>
                                                                        <tr valign="top" align="center">
                                                                          <td style="" valign="top" align="center"><table width="170" border="0" align="center" cellpadding="0" cellspacing="0">
                                                                              <tr>
                                                                                <td valign="top" width="131" align="center"><div align="center">
                                                                                    <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
                                                                                      <tbody>
                                                                                        <tr>
                                                                                          <td height="5"><img src="spacer.gif" width="1" height="1" /></td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                          <td height="30" align="center"><a href="chitietSP.php?idSP=<?php echo $row_sanpham['idSP']; ?>" class="sanpham"><?php echo $row_sanpham['TenSP']; ?></a></td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                          <td height="5"><img src="spacer.gif" width="1" height="1" /></td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                          <td height="100" align="center"><a href="chitietSP.php?idSP=<?php echo $row_sanpham['idSP']; ?>"><img src="UploadImage/SanPham/<?php echo $row_sanpham['HinhAnh']; ?>" width="125" height="125" border="0" /></a></td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                          <td height="5"><img src="spacer.gif" width="1" height="1" /></td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                          <td class="gia" align="center"><?php echo number_format($row_sanpham['DonGia']); ?>&nbsp;VNĐ</td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                          <td class="price2" align="center"></td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                          <td height="5"><img src="spacer.gif" width="1" height="1" /></td>
                                                                                        </tr>
                                                                                      </tbody>
                                                                                    </table>
                                                                                </div>
                                                                                    <p align="center"></p></td>
                                                                              </tr>
                                                                          </table></td>
                                                                        </tr>
                                                                        <tr valign="top" align="center">
                                                                          <td valign="top" align="center" background="dot_horz.htm" height="1"></td>
                                                                        </tr>
                                                                      </tbody>
                                                                  </table></td>
                                                                  <?php
$row_sanpham = mysql_fetch_assoc($sanpham);
    if (!isset($nested_sanpham)) {
      $nested_sanpham= 1;
    }
    if (isset($row_sanpham) && is_array($row_sanpham) && $nested_sanpham++ % 3==0) {
      echo "</tr><tr>";
    }
  } while ($row_sanpham); //end horizontal looper version 3
?>
                                                                </tr>
                                                              </table>
                                                           

                                                            </div>
                                                            <div id="thanhphantrang" align="center">
                                                              <table border="0" align="center" id="phantrang">
                                                                <tr>
                                                                  <td><?php if ($pageNum_sanpham > 0) { // Show if not first page ?>
                                                                      <a href="<?php printf("%s?pageNum_sanpham=%d%s", $currentPage, 0, $queryString_sanpham); ?>">Trang đầu</a>
                                                                      <?php } // Show if not first page ?>
                                                                  </td>
                                                                  <td><?php if ($pageNum_sanpham > 0) { // Show if not first page ?>
                                                                      <a href="<?php printf("%s?pageNum_sanpham=%d%s", $currentPage, max(0, $pageNum_sanpham - 1), $queryString_sanpham); ?>">Trang trước</a>
                                                                      <?php } // Show if not first page ?>
                                                                  </td>
                                                                  <td><?php if ($pageNum_sanpham < $totalPages_sanpham) { // Show if not last page ?>
                                                                      <a href="<?php printf("%s?pageNum_sanpham=%d%s", $currentPage, min($totalPages_sanpham, $pageNum_sanpham + 1), $queryString_sanpham); ?>">Trang kế</a>
                                                                      <?php } // Show if not last page ?>
                                                                  </td>
                                                                  <td><?php if ($pageNum_sanpham < $totalPages_sanpham) { // Show if not last page ?>
                                                                      <a href="<?php printf("%s?pageNum_sanpham=%d%s", $currentPage, $totalPages_sanpham, $queryString_sanpham); ?>">Trang cuối</a>
                                                                      <?php } // Show if not last page ?>
                                                                  </td>
                                                                </tr>
                                                              </table>
                                                              
                                                              <p>
                                                                <?php
for ($i = $TFM_startLink; $i <= $TFM_endLink; $i++) {
  $TFM_LimitPageEndCount = $i -1;
  if($TFM_LimitPageEndCount != $pageNum_sanpham) {
    printf('<a href="'."%s?pageNum_sanpham=%d%s", $currentPage, $TFM_LimitPageEndCount, $queryString_sanpham.'">');
    echo "$i</a>";
  }else{
    echo "<strong>$i</strong>";
  }
if($i != $TFM_endLink) echo("-");}
?>
                                                                </p>
                                                            </p>
                                                            </div> <!-- End DIV Phan Trang -->
                                                            
                                                            </td>
                                                        </tr>
                                                      </tbody>
                                                  </table></td>
                                                </tr>
                                              </tbody>
                                          </table></td>
                                        </tr>
                                      </tbody>
                                  </table></td>
                                <td bgcolor="#FFFFFF"><img src="images/spacer.gif" width="1" height="1" /></td>
                              </tr>
                              <tr>
                                <td><img src="images/bc-u-l.gif" width="9" height="11" /></td>
                                <td bgcolor="#FFFFFF"><img src="images/spacer.gif" width="1" height="1" /></td>
                                <td><img src="images/bc-u-r.gif" width="11" height="11" /></td>
                              </tr>
                            </tbody>
                        </table></td>
                      </tr>
                    </table>
                </div></td>
              </tr>
            </tbody>
          </table></td>
        </tr>
      </table>
  
    </div> <!-- End div content -->
  </div><!-- End div Main -->
  <div id="footer">
  <?php include("footer.php"); ?>
  </div>
</div>
</body>
</html>
<?php
mysql_free_result($sanpham);
?>
